exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseController {
  __before() {// 前置操作，在action执行，返回false则终止当前控制器
  }
  getDepartNameAction() {
    var _this = this;

    return _asyncToGenerator(function* () {
      // 查询部门名称
      const aj = think.ajaxJson();
      const departService = _this.service('sys/DepartService');
      const res = yield departService.getDepartName(_this.getUser());
      if (!res.error) {
        aj.success = res.success;
        aj.msg = res.msg;
        aj.result = res.result;
      } else {
        aj.success = false;
        aj.msg = `查询失败:${res.error}`;
      }
      return _this.json(aj);
    })();
  }
  getDepartNameAllAction() {
    var _this2 = this;

    return _asyncToGenerator(function* () {
      // 查询部门名称
      const aj = think.ajaxJson();
      const departService = _this2.service('sys/DepartService');
      const res = yield departService.getDepartNameAll();
      if (!res.error) {
        aj.success = res.success;
        aj.msg = res.msg;
        aj.result = res.result;
      } else {
        aj.success = false;
        aj.msg = `查询失败:${res.error}`;
      }
      return _this2.json(aj);
    })();
  }

  getDepartListAction() {
    var _this3 = this;

    return _asyncToGenerator(function* () {
      // 查询部门信息
      const aj = think.ajaxJson();
      const getData = {
        org_type: _this3.get('org_type')
      };
      const departService = _this3.service('sys/DepartService');
      const res = yield departService.getDepartList(getData, _this3.getUser());
      if (!res.error) {
        aj.success = res.success;
        aj.msg = res.msg;
        aj.result = res.result;
      } else {
        aj.success = false;
        aj.msg = `查询失败:${res.error}`;
      }
      return _this3.json(aj);
    })();
  }

  saveDepartInfoAction() {
    var _this4 = this;

    return _asyncToGenerator(function* () {
      // 保存部门信息
      const aj = think.ajaxJson();
      const postData = _this4.post('id,org_name,description,parent_id,org_code,org_type,parent_ids,parent,primary_pe' + 'rson,sort,deputy_person,area_id');
      const departService = _this4.service('sys/DepartService');
      const res = yield departService.saveDepartInfo(postData);
      if (!res.error) {
        aj.success = res.success;
        aj.msg = res.msg;
        aj.result = res.result;
      } else {
        aj.success = false;
        aj.msg = `查询失败:${res.error}`;
      }
      return _this4.json(aj);
    })();
  }

  delDepartInfoAction() {
    var _this5 = this;

    return _asyncToGenerator(function* () {
      // 删除部门信息
      const aj = think.ajaxJson();
      const postData = {
        id: _this5.post('id')
      };
      if (postData.id) {
        const departService = _this5.service('sys/DepartService');
        const res = yield departService.delDepartInfo(_this5.post());
        if (!res.error) {
          aj.success = res.success;
          aj.msg = res.msg;
          aj.result = res.result;
        } else {
          aj.success = false;
          aj.msg = `查询失败:${res.error}`;
        }
      } else {
        aj.success = false;
        aj.msg = '没有接收到相关参数';
      }
      return _this5.json(aj);
    })();
  }
  /** *****************与用户有关****************** */
  getUserListByDidAction() {
    var _this6 = this;

    return _asyncToGenerator(function* () {
      // 根据部门id获取用户列表
      const aj = think.ajaxJson();
      const UserService = _this6.service('sys/UserService'); // 调用userservice
      const getData = _this6.get('page,pageSize,options');
      const res = yield UserService.getUserList(getData);
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '查询失败';
      }
      return _this6.json(aj);
    })();
  }
  unBindUserAction() {
    var _this7 = this;

    return _asyncToGenerator(function* () {
      // 用户部门解绑
      // console.log(this.post());
      const aj = think.ajaxJson();
      const postData = {
        userid: _this7.post('userid')
      };
      const departService = _this7.service('sys/DepartService');
      const res = yield departService.unBindUser(postData);
      if (!res.error) {
        aj.success = res.success;
        aj.msg = res.msg;
        aj.result = res.result;
      } else {
        aj.success = false;
        aj.msg = `查询失败:${res.error}`;
      }
      return _this7.json(aj);
    })();
  }

  getUserNotBindOrgAction() {
    var _this8 = this;

    return _asyncToGenerator(function* () {
      // 获取未绑定组织机构的警员
      const aj = think.ajaxJson();
      const getData = _this8.get('page,pageSize,options');
      const departService = _this8.service('sys/DepartService');
      const res = yield departService.getUserNotBindOrg(getData);
      if (!res.error) {
        aj.success = res.success;
        aj.msg = res.msg;
        aj.result = res.result;
      } else {
        aj.success = false;
        aj.msg = `查询失败:${res.error}`;
      }
      return _this8.json(aj);
    })();
  }

  saveUsersDepartAction() {
    var _this9 = this;

    return _asyncToGenerator(function* () {
      // 保存用户信息
      const postData = _this9.post('userlist,org_id');
      const aj = think.ajaxJson();
      const departService = _this9.service('sys/DepartService');
      const res = yield departService.saveUsersDepart(postData);
      if (!res.error) {
        aj.success = res.success;
        aj.msg = res.msg;
        aj.result = res.result;
      } else {
        aj.success = false;
        aj.msg = `查询失败:${res.error}`;
      }
      return _this9.json(aj);
    })();
  }

  // 获取所有组织机构和人员
  orgAndUserAction() {
    var _this10 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const data = _this10.get();
      const orgUserService = _this10.service('sys/DepartService');
      const result = yield orgUserService.getOrgAndUser(_this10.getUser());

      if (!result.error) {
        aj.result = result;
      } else {
        aj.success = false;
        aj.msg = '查询失败';
      }
      return _this10.json(aj);
    })();
  }
  __after() {// 后置操作,在action调用之后执行

  }

  __call() {// 魔术函数

  }
};
;